#include "myScreen.h"

MyScreen::MyScreen()
{
}

MyScreen::~MyScreen()
{
}

void MyScreen::Render()
{
	// Normal loop
	this->pEngine->GetGraphics()->DrawSprite(this->pMySprite0);
	this->pEngine->GetGraphics()->SetModelViewMatrix(Matrix::Identity());

	// Loop back
	this->pEngine->GetGraphics()->DrawSprite(this->pMySprite1);
	this->pEngine->GetGraphics()->SetModelViewMatrix(Matrix::Identity());

	// Play once
	this->pEngine->GetGraphics()->DrawSprite(this->pMySprite2);
	this->pEngine->GetGraphics()->SetModelViewMatrix(Matrix::Identity());
}

void MyScreen::Update(float fDelta)
{
	this->pMySprite0->Update(fDelta);
	this->pMySprite1->Update(fDelta);
	this->pMySprite2->Update(fDelta);
}

void MyScreen::Load()
{
	this->pMyTexture = this->pEngine->GetGraphics()->LoadTexture("media/animation.jpg");

	this->pMySprite0 = new Sprite(this->pMyTexture, 96, 96);	// We create a sprite using the texture
	this->pMySprite0->SetHandlePosition(0.5f, 0.5f);			// By setting the handle to .5 the sprite will be
																// rendered centered about its self.
	this->pMySprite0->SetPosition((this->ScreenWidth() / 2.0f), this->ScreenHeight() / 2.0f);

	this->pMySprite0->AddAnimation("Simple", 0, 3, 1.0f);
	this->pMySprite0->PlayAnimation("Simple", DelGEGraphics_Animation_Playstyle_Loop);

	this->pMySprite1 = new Sprite(this->pMyTexture, 96, 96);	// We create a sprite using the texture
	this->pMySprite1->SetHandlePosition(0.5f, 0.5f);			// By setting the handle to .5 the sprite will be
																// rendered centered about its self.
	this->pMySprite1->SetPosition((this->ScreenWidth() / 2.0f) + (this->pMySprite1->GetWidth() + 50.0f), this->ScreenHeight() / 2.0f);
	this->pMySprite1->SetColor(Color(0, 255, 0));

	this->pMySprite1->AddAnimation("Simple", 0, 3, 1.0f);
	this->pMySprite1->PlayAnimation("Simple", DelGEGraphics_Animation_Playstyle_Loopback);

	this->pMySprite2 = new Sprite(this->pMyTexture, 96, 96);	// We create a sprite using the texture
	this->pMySprite2->SetHandlePosition(0.5f, 0.5f);			// By setting the handle to .5 the sprite will be
																// rendered centered about its self.
	this->pMySprite2->SetPosition((this->ScreenWidth() / 2.0f) - (this->pMySprite2->GetWidth() + 50.0f), this->ScreenHeight() / 2.0f);
	this->pMySprite2->SetColor(Color(255, 0, 0));

	this->pMySprite2->AddAnimation("Simple", 0, 3, 1.0f);
	this->pMySprite2->PlayAnimation("Simple", DelGEGraphics_Animation_Playstyle_Once);
}

void MyScreen::Unload()
{
	this->pEngine->GetGraphics()->UnloadTexture(this->pMyTexture);

	delete this->pMySprite0;
	delete this->pMySprite1;
	delete this->pMySprite2;
}